package com.ccrfid.rmc6.service.device;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.device.*;
import com.ccrfid.rmc6.entity.personnel.PersonnelView;
import com.ccrfid.rmc6.lbservice3.pojo.msg.MsgLocateActive;
import com.ccrfid.rmc6.repository.search.SearchCriteria;
import org.hibernate.type.IntegerType;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Map;

public interface CardService {
    //
    Page<CardView> getCardInfoPage(SearchCriteria criteria, Pageable pageable);
    //
    CardEntity getCardById(Long cardId);
    //
    @Cacheable(value = "cards", key = "#cardNumber")
    CardEntity getCardByCardNumber(Long cardNumber);
    //
    @Cacheable(value = "cards2", key = "#hexNumber")
    CardEntity getCardByHexNumber(String hexNumber);
    //
    @Caching(
            put = {
                    @CachePut(value = "cards", key = "#result.cardNumber", condition = "#result.cardNumber != null"),
                    @CachePut(value = "cards2", key = "#result.hexNumber", condition = "#result.hexNumber != null")
            })
    CardEntity createCard(CardEntity entity) throws AppException;
    //
    @Caching(
            put = {
                    @CachePut(value = "cards", key = "#result.cardNumber", condition = "#result.cardNumber != null"),
                    @CachePut(value = "cards2", key = "#result.hexNumber", condition = "#result.hexNumber != null")
            })
    CardEntity updateCard(Long cardId, CardEntity entity) throws AppException;
    //
    @Caching(
            put = {
                    @CachePut(value = "cards", key = "#result.cardNumber", condition = "#result.cardNumber != null"),
                    @CachePut(value = "cards2", key = "#result.hexNumber", condition = "#result.hexNumber != null")
            })
    CardEntity updateCard(CardEntity entity);
    //
    PersonnelView getCardBindPersonnelInfo(Long cardId);
    //
    @CacheEvict(value = {"cards", "cards2"}, allEntries = true)
    int deleteCards(List<Long> idList);
    //
    List<CardActiveView> getAllCardActives();
    //
    List<CardEntity> getAllCards();
    //
    CardActiveEntity updateCardActive(MsgLocateActive msgLocateActive);
    //
    CardActiveEntity getCardActive(Long cardNumber);

    Page<UntreatedCardDto> getCardStatisticPage(Map<String,Integer> param, Pageable pageable);

    Page<CardView> getCardInfo(String sql, Pageable pageable);

    Page<CardView> getCardInfoHuaihua(String sql, List<Long> orgIdList, Pageable pageable);

    Integer getLowpower(int enabled, int lowPowerStatu, int bindStatus, Integer personnelType, List<Long> orgIdList);

    Integer getCutOff(int enabled, int cutOffStatu,int bindStatus, Integer personnelType, List<Long> orgIdList);

    Integer getOffline(int enabled, int onlineStatu,int bindStatus, Integer personnelType, List<Long> orgIdList);


}
